home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue62 / outlook / OutlookHelper / MainForm.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-08-12  |  1.8 KB  |  74 lines

  1. unit MainForm;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, OleServer, Outlook8, Outlook, PipeServer;
  8.  
  9. type
  10.   THelperMainForm = class(TForm)
  11.     HelperActive: TCheckBox;
  12.     Label1: TLabel;
  13.     Log: TMemo;
  14.     FreeObjects: TButton;
  15.     ClearLog: TButton;
  16.     procedure FormCreate(Sender: TObject);
  17.     procedure ClearLogClick(Sender: TObject);
  18.     procedure FreeObjectsClick(Sender: TObject);
  19.   private
  20.     { Private declarations }
  21.     pstThread : TPipeServerThread;
  22.     Procedure SendObjectFreeCommand;
  23.   public
  24.     { Public declarations }
  25.     Procedure LogMessage(strMessage : String);
  26.   end;
  27.  
  28. var
  29.   HelperMainForm: THelperMainForm;
  30.  
  31. implementation
  32.  
  33. {$R *.DFM}
  34.  
  35. Procedure THelperMainForm.LogMessage(strMessage : String);
  36. Begin
  37.   Log.Lines.Insert(0,DateTimeToStr(Now)+': '+strMessage+'.');
  38. End;
  39.  
  40. procedure THelperMainForm.FormCreate(Sender: TObject);
  41. begin
  42.   pstThread := TPipeServerThread.Create(False);
  43. end;
  44.  
  45. Procedure THelperMainForm.SendObjectFreeCommand;
  46. Var
  47.   hPipe : THandle;
  48.   iBW   : Cardinal; { bytes written, bytes read }
  49.  
  50. Begin
  51.   {
  52.   The FREE command is sent so that the pipe server thread can properly shut down.
  53.   This is needed because otherwise the connection to Outlook will persist even
  54.   though this application has been closed. Simply closing the application
  55.   won't properly terminate the thread as ConnectNamedPipe is a blocking function.
  56.   }
  57.   hPipe := CreateFile(strPipeName,Generic_Write,0,nil,Open_Existing,0,0);
  58.   WriteFile(hPipe,'FREE',4,iBW,nil);
  59.   CloseHandle(hPipe);
  60. End;
  61.  
  62. procedure THelperMainForm.ClearLogClick(Sender: TObject);
  63. begin
  64.   Log.Clear;
  65. end;
  66.  
  67. procedure THelperMainForm.FreeObjectsClick(Sender: TObject);
  68. begin
  69.   pstThread.Terminate;
  70.   SendObjectFreeCommand;
  71. end;
  72.  
  73. end.
  74.